package pers.gxm.proxy;

public class Printer implements Printable{
    public static void main(String[] args) {
//        Printable alice = new PrinterProxy("Alice");
        Printable alice = new PrinterProxy("God","pers.gxm.proxy.Printer");
        System.out.println("名字 = " + alice.getPrinterName());
        alice.setPrinterName("Bob");
        System.out.println("名字 = " + alice.getPrinterName());
        alice.print("Hello,World.");
    }
    private String name;
    public Printer(){
        this("");
    }
    public Printer(String name){
        this.name = name;
        heavyJob("正在生成实例（" + name + ")");
    }


    @Override
    public void setPrinterName(String name) {
        this.name = name;
    }

    @Override
    public String getPrinterName() {
        return name;
    }

    @Override
    public void print(String string) {
        System.out.println("====" + name + "====");
        System.out.println(string);
    }

    private void heavyJob(String msg){
        System.out.println(msg);
        for(int i = 0;i < 5;i++){
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.print(".");
        }
        System.out.println("end");
    }
}
